home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-2.iso / Files II / Hyper / T / ToolKit 5.0.1.sit / ToolKit™ / ToolKit™ XCMDs / ToolKit™ XCMDs.rsrc / TEXT_18981_TKdoTEXT.txt < prev    next >
Encoding:
Text File  |  1994-05-12  |  9.3 KB  |  183 lines

  1. TKdoTEXT
  2.  
  3.       XFCN
  4.       No. 4401
  5.       Version:  5.0 (ONLY for Registered owners of ToolKit‚Ñ¢)
  6.       Copyright ¬© 1990 - 1994 by Stan Gilbert
  7. _____________________________________________________
  8.  
  9. TKdoTEXT allows fast retrieval of TEXT stored as TEXT resources in the stack eliminating the overhead of hiding and showing different fields.  You can store formatted TEXT, item lists for menus, preferences, compare lists, action lists, and even scripts.  Another advantage is that all the TEXT resources are global to the stack.
  10.                          ∂
  11. Examples - Using Styled Text
  12.  
  13. √ì√äget TKdoTEXT("myText","styl","List")
  14. √ä√ä‚Ä∫- display "myText" with style in cd fld "List"
  15.  
  16. √ä√ä‚Ä∫get TKdoTEXT("myText","styl,bg","List")
  17. √ä√ä‚Ä∫- display "myText" with style in BkGnd fld "List"
  18.  
  19. √ä√ä‚Ä∫get TKdoTEXT("myText","sav,styl","List")
  20. √ä√ä‚Ä∫- save cd fld "List" with  styling as resource "myText"
  21.  
  22. √ä√ä‚Ä∫get TKdoTEXT("myText","sav,styl,bg","List")
  23. √ä√ä‚Ä∫- save bkgnd fld "List" with  styling as resource "myText"
  24.  
  25.  
  26. Using Styled Text
  27.  
  28. get TKdoTEXT("myText","styl","List")
  29.  
  30. This will fetch the 'TEXT' resource "myText" and put it into the (default) card field "List" with styling.  Notice we get TKdoTEXT and we do NOT put TKdoTEXT because there is no normal target to the put command (the message window would pop up).  This is because the XCMD must display the text into the HyperCard‚Ñ¢ field in order to apply the 'STYL' resource to it.  In this case TKdoTEXT assumes the existence of a CARD field named "List" because the BG specifier is not included in parameter 2.
  31.  
  32. ‚Äû¬†If the target field does not exist TKdoTEXT will beep and display the appropriate error message in the message window.
  33.  
  34. √笆You may be wondering why we simply cannot put cd fld "List" into the third parameter.  That would pass the contents of cd fld "List" and not a description of the target field.  The XFCN could have been written to accept the description in quotes:  "cd fld List", however, this would not work if the name of the field were longer than one word.  Multiple word names must, themselves, be in quotes which would create a parameter with double quotes in it: "cd fld "my List""
  35.  
  36. get TKdoTEXT("myText","styl,bg","List")
  37.  
  38. This is similar to the example above.  The only difference is we are specifying a BACKGROUND field be used by including the BG specifier in parameter 2.  It will fetch the 'TEXT' resource "myText" and put it into BACKGROUND field "List" WITH styling.  Notice we get TKdoTEXT and we do NOT put TKdoTEXT.  This is because the XCMD must display the text into the HyperCard‚Ñ¢ field in order to apply the 'STYL' resource and style it. 
  39.  
  40. get TKdoTEXT("myText","sav,styl","List")
  41.  
  42. This will fetch the contents of card field "List" and save it as a 'TEXT' resource named "myText".  It will also preserve the styling of the text in a 'STYL' resource of the same name.  Notice we get TKdoTEXT and we do NOT put TKdoTEXT since we are only interested in saving the text, not displaying it.  The Short Name of the field is in parameter 3.  It defaults to a CARD field because no BG specifier is used in parameter 2.  Any 'TEXT' or 'STYL' resource that may pre-exist this save is overwritten and cannot be retrieved.
  43.  
  44. get TKdoTEXT("myText","sav,styl,bg","List")
  45.  
  46. This will fetch the contents of BACKGROUND field "List" and save it as a 'TEXT' resource named "myText" because we have included the BG specifier in parameter 2.  It will also preserve the styling of the text in a 'STYL' resource of the same name.  Notice we get TKdoTEXT and we do NOT put TKdoTEXT since we are only interested in saving the text, not displaying it.  The Short Name of the field is in parameter 3.  Any 'TEXT' or 'STYL' resource that may pre-exist this save is overwritten and cannot be retrieved.
  47.  
  48.  
  49. Examples - without styling
  50.  
  51. √ì√äget TKdoTEXT("myText")
  52. √ä√ä‚Ä∫- fetch 'TEXT' resource "myText"
  53.  
  54. √ä√ä‚Ä∫put TKdoTEXT("myText") into cd fld "List"
  55. √ä√ä‚Ä∫- display "myText" without style in cd fld "List"
  56.  
  57. √ä√ä‚Ä∫get TKdoTEXT("myText","sav",cd fld "List")
  58. √ä√ä‚Ä∫- save cd fld "List" without styling as resource "myText"
  59.  
  60. √ä√ä‚Ä∫get TKdoTEXT("myText","del")
  61. √ä√ä‚Ä∫- delete "myText" 'TEXT' and 'STYL' resources
  62.  
  63.  
  64. Using Text Without Styling
  65.  
  66. get TKdoTEXT("myText")
  67.  
  68. will fetch the 'TEXT' resource "myText" and hold it in the HyperCard‚Ñ¢ global "it".  No styling is applied.  See "More Information" below for hints on this usage.
  69.  
  70. put TKdoTEXT("myText") into cd fld "List"
  71.  
  72. will fetch the 'TEXT' resource "myText" and put it into card field "List".  No styling is applied.
  73.  
  74. get TKdoTEXT("myText","sav",cd fld "List")
  75.  
  76. This will fetch the contents of card field "List", as specified by parameter 3, and save it as a 'TEXT' resource named "myText".  Notice we get TKdoTEXT and we do NOT put TKdoTEXT since we are only interested in saving the text, not displaying it.  No styling is preserved and any 'TEXT' or 'STYL' resource that may pre-exist this save is destroyed and cannot be retrieved.
  77.  
  78. get TKdoTEXT("myText","del")
  79.  
  80. This will delete any 'TEXT' and 'STYL' resource named "myText".  It cannot be undone!
  81.  
  82.  
  83. Parameters
  84.  
  85. Parameter 1 
  86.  
  87. rName:  This MUST be the first item and always refers to the name of the TEXT resource to be used by TKdoTEXT.
  88.  
  89. Parameter 2  (items are separated by commas)
  90.  
  91. save:  This first removes any existing 'TEXT' and 'STYL' resource named rName.  It then saves the text designated by parameter 2 to a 'TEXT' resource named rName.  No 'STYL' resource is created unless the STYL command specifier is also used (see below).
  92.  
  93. style:  This command specifier is used to SAVe or Display a TEXT resource.
  94.  
  95. If the SAVe specifier is used then a 'STYL' resource is created for the text.  This assumes the source of the text is a HyperCard‚Ñ¢ field.  HyperCard‚Ñ¢ containers holding text do NOT maintain styling.
  96.  
  97. If the SAVe specifier is NOT used then it is assumed you are attempting to display a 'TEXT' resource in a HyperCard‚Ñ¢ field and the short name of the field must exist (in quotes) as parameter 3 for TKdoTEXT.  The default is a CARD field.  If you are attempting to display into a BACKGROUND field then the BG specifier (below) must also be included in the parameter 2 list.  See the examples for more detail.
  98.  
  99. bg:  is ONLY used with STYL and specifies that a BACKGROUND field is the target for text to be displayed with styling.
  100.  
  101. delete:  will remove the 'TEXT' and 'STYL' resource named rName.
  102.  
  103.  
  104. Parameter 3
  105.  
  106. Short name:  used ONLY with STYL when displaying a 'TEXT' with styling into a HyperCard‚Ñ¢ field.
  107.  
  108.     - or -
  109.  
  110. container name:  passed for SAVing a HyperCard‚Ñ¢ container or field to a 'TEXT' resource WITHOUT styling.
  111.  
  112.  
  113. Requirements
  114.  
  115. Ó none
  116.  
  117.  
  118. Return Values
  119.  
  120. Returns the TEXT resource if SAVE or DELETE are NOT used, otherwise, nothing is returned.
  121.  
  122. √ç If you are trying to retrieve a 'TEXT' resource and it does NOT exist you will get a beep!
  123.  
  124.  
  125. Related Topics
  126.  
  127. √쬆See TKpopMenu to use TEXT resources as item lists.
  128.  
  129.  
  130. Special Features
  131.  
  132. TKdoTEXT is excellent for storing TEXT resources in your stacks as item lists for popUp menus using TKpopMenu.  This is very fast and allows the item list to be global to the stack.  TKdoTEXT allows FAST retrieval so the item list can be altered before displaying the menu to the user.
  133.  
  134. TKdoTEXT is also a clean way to store TEXT as an alternative to having different blocks of TEXT in several fields and then hiding or showing the fields as desired.  Since the text is NOT compressed in any way the space required for the text itself is the same, however, the overhead for having and maintaining several fields is eliminated.
  135.  
  136.  
  137. More Information
  138.  
  139. TKdoTEXT can be used to store "Action Lists".  As an example, if a menu had "Help" in it and the user selected "Help" you could retrieve the menu action list and direct the action according to the second item in the selection line.  This can reduce scripting tremendously by eliminating all the conditional statements for each item of the menu.  For example, if a menu had 10 items in it it would normally require ten conditional statements:
  140.  
  141.      get TKpopMenu("myMenu")
  142.  
  143.      if it = "Open‚Ķ" then       -- item  1
  144.        doOpen
  145.      else if it = "Close‚Ķ" then -- item  2
  146.        doClose
  147.          ‚Ä¢
  148.          ‚Ä¢                      -- items 3-9
  149.          ‚Ä¢
  150.      else if it = "Help" then   -- item 10
  151.        go stack "Help"
  152.      end if
  153.  
  154. However, if the popUp menu XCMD returns the name of the item selected then you can fetch an action list for that menu and perform handler specified by the list.  The action list might look similar to this:
  155.     _____________________
  156.     Open‚Ķ,doOpen
  157.     Close‚Ķ,doClose
  158.       ‚Ä¢
  159.       ‚Ä¢
  160.       ‚Ä¢
  161.     Help,go stack "Help"
  162.     _____________________
  163.  
  164.     on doPopMenu mName,L,T
  165.       get TKpopMenu(mName,L,T)
  166.       if it = "" then exit doPopMenu
  167.  
  168.       get TKdoTEXT(mName & ".action")
  169.       repeat with i = 1 to number of lines in it
  170.         if item 1 of line i of it = what then
  171.           do (item 2 of line i of it)
  172.           exit doMenu
  173.         end if
  174.       end repeat
  175.     end doPopMenu
  176.  
  177. This makes it really easy to update the action list and makes it simple to create a single handler for any menu simply by passing the name of the 'TEXT' resource to it.
  178.  
  179. The drawback to this is maintaining the code.  It is not apparent what you are trying to do unless you have access to the action list.
  180.  
  181.  
  182. °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
  183.